<!DOCTYPE html>
<!--
Copyright (c) 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/core/test_utils.html">
<link rel="import" href="/tracing/extras/measure/measure.html">
<link rel="import" href="/tracing/model/model.html">

<script>
'use strict';

tr.b.unittest.testSuite(function() {
  const AsyncSlice = tr.model.AsyncSlice;
  const MeasureAsyncSlice = tr.e.measure.MeasureAsyncSlice;

  test('basic', function() {
    const s = new MeasureAsyncSlice(
        'blink.user_timing', 'createImports', 7, 0, {});
    s.duration = 100;

    assert.strictEqual(AsyncSlice.subTypes.getConstructor(
        'blink.user_timing', 'createImports'),
    MeasureAsyncSlice);
    assert.strictEqual(s.viewSubGroupTitle, 'Ungrouped Measure');
  });

  test('import', function() {
    const events = [
      {name: 'createImports', args: {}, pid: 1, ts: 100,
        cat: 'blink.user_timing', tid: 2, ph: 'b', id: 71},
      {name: 'createImports', args: {}, pid: 1, ts: 200,
        cat: 'blink.user_timing', tid: 2, ph: 'e', id: 71}
    ];
    const m = tr.c.TestUtils.newModelWithEvents([events]);
    const t2 = m.getOrCreateProcess(1).getOrCreateThread(2);
    assert.strictEqual(t2.asyncSliceGroup.length, 1);
    assert.instanceOf(t2.asyncSliceGroup.slices[0], MeasureAsyncSlice);
  });

  test('groupMeasureAsyncSlice', function() {
    const events = [
      {name: 'createImports', args: {}, pid: 1, ts: 100,
        cat: 'blink.user_timing', tid: 2, ph: 'b', id: 71},
      {name: 'createImports', args: {}, pid: 1, ts: 200,
        cat: 'blink.user_timing', tid: 2, ph: 'e', id: 71},
      {name: 'runAutoClosers', args: {}, pid: 1, ts: 210,
        cat: 'blink.user_timing', tid: 2, ph: 'b', id: 72},
      {name: 'runAutoClosers', args: {}, pid: 1, ts: 310,
        cat: 'blink.user_timing', tid: 2, ph: 'e', id: 72}
    ];
    const m = tr.c.TestUtils.newModelWithEvents([events]);
    const t2 = m.getOrCreateProcess(1).getOrCreateThread(2);
    assert.strictEqual(t2.asyncSliceGroup.length, 2);
    assert.strictEqual(t2.asyncSliceGroup.slices[0].title, 'createImports');
    assert.strictEqual(t2.asyncSliceGroup.slices[1].title, 'runAutoClosers');
    assert.instanceOf(t2.asyncSliceGroup.slices[0], MeasureAsyncSlice);
    assert.instanceOf(t2.asyncSliceGroup.slices[1], MeasureAsyncSlice);
  });
});
</script>
